<template>
  <div>
    <el-card class="box-card">
      <div class="BigDiv">
        <el-input class="ElInput" v-model="reportingName"></el-input>
        <el-button icon="el-icon-search" type="primary" @click="getReporting()"></el-button>
        <el-button type="success" @click="toAddReporting()">添加</el-button>
        <!--表格-->
        <el-table
            :data="tableData"
            height="250"
            border
            style="margin-top: 10px;width: 100%">
          <el-table-column
              prop="reportingInstrumentTime"
              label="仪表名称"
              width="180">
          </el-table-column>
          <el-table-column
              prop="reportingName"
              label="创建人"
              width="180">
          </el-table-column>
          <el-table-column
              prop="reportingType"
              label="收费项目"
              width="180">
            <template slot-scope="scope">
              {{scope.row.reportingType ==0?"业务费": scope.row.reportingType == 1? "水费": scope.row.reportingType == 2? "电费": scope.row.reportingType == 3? "燃气费":"收费项目"}}
            </template>
          </el-table-column>
          <el-table-column
              prop="reportingDate"
              label="周期">
          </el-table-column>
          <el-table-column
              prop="reportingStartTime"
              label="开始时间">
          </el-table-column>
          <el-table-column
              prop="reportingEndTime"
              label="结束时间">
          </el-table-column>
          <el-table-column
              prop="createTime"
              label="创建时间">
          </el-table-column>
          <el-table-column
              prop="updateTime"
              label="修改时间">
          </el-table-column>
          <el-table-column
              fixed="right"
              label="操作">
            <template slot-scope="scope">
              <el-button type="primary" @click="toUpdate(scope.row)">修改</el-button>
              <el-button type="warning" @click="delReporting(scope.row.id)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!--表格-->
      </div>
    </el-card>
    <!-- 增改弹窗 -->
    <!-- Form -->
    <el-dialog title="增改"
               :visible.sync="dialogFormVisible"
               :before-close="closeExpertFormDialog">
      <el-form :model="reportingFrom" ref="ruleForm">
        <el-form-item label="仪表名称">
          <el-input v-model="reportingFrom.reportingInstrumentTime"></el-input>
        </el-form-item>
        <el-form-item label="收费项目">
          <el-select v-model="reportingFrom.reportingType">
            <el-option label="业务费" :value="0"></el-option>
            <el-option label="水费" :value="1"></el-option>
            <el-option label="电费" :value="2"></el-option>
            <el-option label="燃气费" :value="3"></el-option>s
          </el-select>
        </el-form-item>
        <el-form-item label="抄表周期">
          <el-date-picker
            v-model="reportingFrom.reportingDate"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="周期">
        </el-date-picker>
        </el-form-item>
        <el-form-item label="开始时间">
          <el-date-picker
              v-model="reportingFrom.reportingStartTime"
              type="datetime"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="启用日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间">
          <el-date-picker
              v-model="reportingFrom.reportingEndTime"
              type="datetime"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="启用日期">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="resetForm('ruleForm')">取 消</el-button>
        <el-button type="primary" @click="saveOrUpdateReporting('insert')">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 增改弹窗 -->
    <!-- Form -->
    <!--分页-->
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page=pageRquset.pageNum
        :page-sizes="[5, 10, 20, 30]"
        :page-size=pageRquset.pageSize
        layout="total, sizes, prev, pager, next, jumper"
        :total=total>
    </el-pagination>
    <!--分页-->
  </div>
</template>

<script>
export default {
  /*Data*/
  data() {
    return {
      pageRquset: {
        pageSize: 5,
        pageNum: 1
      },
      reportingFrom:{
        id:0,
        reportingName:'',
        reportingType:'',
        reportingDate:'',
        reportingStartTime:'',
        reportingEndTime:'',
        reportingInstrumentTime:'',
        reportingInstrumentId:'',
        reportingMonth:'',
        createTime:'',
        updateTime:'',
        reportingDelFlag:'',
      },
      restReportingFrom:{
        id:0,
        reportingName:'',
        reportingType:'',
        reportingDate:'',
        reportingStartTime:'',
        reportingEndTime:'',
        reportingInstrumentTime:'',
        reportingInstrumentId:'',
        reportingMonth:'',
        createTime:'',
        updateTime:'',
        reportingDelFlag:'',
      },
      currentPage2: 1,
      total:0,
      input: '',
      dialogTableVisible: false,
      dialogFormVisible: false,
      reportingName:'',
      tableData: [],
    }
  },
  /*自动挂载*/
  mounted() {
    this.getReporting()
  },
  /*函数*/
  methods:{
    /*抄表周期全查*/
    getReporting () {
      this.$axios.get('/memberLwh/reporting/getReporting', {
        params: {
          reportingName: this.reportingName,
          pageSize: this.pageRquset.pageSize,
          pageNum: this.pageRquset.pageNum
        }
      }).then(res => {
        this.tableData = res.data.obj.content
        this.total = res.data.obj.total
        console.log(res.data.obj.content)

      }).catch(error => {
        console.log(error)
      })
    },
// 添加点击X关闭是清空from表单数据
    closeExpertFormDialog (done) {
      this.$refs.ruleForm.resetFields()
      done()// done 用于关闭 Dialog
      this.reportingFrom = {}
    },
    // 添加弹窗里的取消按钮 点击取消是清空from表单数据
    resetForm (formName) {
      this.$refs[formName].resetFields()
      this.dialogFormVisible = false
      this.reportingFrom = {}
    },
    //添加按钮
    toAddReporting(){
      this.dialogFormVisible = true
      this.reportingFrom = {
        id: 0
      }
    },
    // 抄表增改
    saveOrUpdateReporting (formName) {
      // const formData = new FormData()
      this.$axios.post('/memberLwh/reporting/saveOrUpdateReporting', this.reportingFrom
      ).then(res => {
        if (res.data.code === 200) {
          this.dialogFormVisible = false
          this.reportingFrom = this.restReportingFrom
          this.MyMessage("成功","sussess")
          this.getReporting()
        } else {
          this.MyMessage('失败', 'warning')
          this.insertLog("抄表增改")
          this.getReporting()
        }
      })
    },
    // 修改的回显
    toUpdate (reporting) {
      this.reportingFrom = reporting
      this.dialogFormVisible = true
    },
    /*分页*/
    handleSizeChange (val) {
      this.pageRquset.pageSize = val
      this.getReporting()
    },
    handleCurrentChange (val) {
      this.pageRquset.pageNum = val
      this.getReporting()
    },
    /*抄表周期删除*/
    delReporting (id) {
      debugger
      this.$confirm('是否删除这条数据', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$axios.delete('/memberLwh/reporting/delReporting', {
          params: {
            id: id
          }
        }).then(res => {
          if (res.data.code === 200) {
            this.MyMessage('删除成功', 'sussess')
            this.getReporting()
          } else {
            this.MyMessage('删除失败', 'warning')
          }
        }).catch(res => {
          this.insertLog("周期抄表删除")
          this.MyMessage('删除失败,请联系管理员', 'error')
        })
      }).catch(() => {
        this.MyMessage('已取消删除', 'info')
      })
    },
    /*提示框*/
    MyMessage (msg, type) {
      this.$notify({
        showClose: true,
        message: msg,
        type: type
      })
    },
  }
}
</script>

<style>
*{
  margin: 0;
  padding: 0;
}
.ElInput{
  width: 200px;
}
.box-card{
  height: 820px;
  margin: 10px;
}
</style>